package models;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Query;

import play.db.jpa.JPA;
import play.db.jpa.Model;

@Entity
public class Video extends Model{
	
	private String name;
	private String address;
	private String type;
	
	@OneToMany(mappedBy = "video", cascade = CascadeType.ALL)
	private List<CommentVideo> commentVideoList;
	
	@ManyToOne
	private Serie serie;
	
	@ManyToOne
	private User user;
	
	
	public Video(String name, String address, String type,
			List<CommentVideo> commentVideoList, Serie serie, User user) {
		super();
		this.name = name;
		this.address = address;
		this.type = type;
		this.commentVideoList = new ArrayList<CommentVideo>();
		this.serie = serie;
		this.user = user;
	}

	public Video(String name, String address, String type, Serie serie, User user) {
		super();
		this.name = name;
		this.address = address;
		this.type = type;
		this.commentVideoList = new ArrayList<CommentVideo>();
		this.serie = serie;
		this.user = user;
	}

	public Video(String name, String address, String type,
			List<CommentVideo> commentVideoList, Serie serie) {
		super();
		this.name = name;
		this.address = address;
		this.type = type;
		this.commentVideoList = commentVideoList;
		this.serie = serie;
	}
	
	
	

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public List<CommentVideo> getCommentVideoList() {
		return commentVideoList;
	}

	public void setCommentVideoList(List<CommentVideo> commentVideoList) {
		this.commentVideoList = commentVideoList;
	}

	public Serie getSerie() {
		return serie;
	}

	public void setSerie(Serie serie) {
		this.serie = serie;
	}
	
	public static List<Video> getAllVideos(long serieId){
		
		Query query = JPA.em().createQuery("select v from Video v where v.serie.id = "
				+ serieId + " order by v.id desc");
		return query.getResultList();
	} 
	
	

}
